<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我是“端阳王”</title>
    <!--定宽， 通过游览器自动缩放（等比）-->
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <meta name="apple-touch-fullscreen" content="YES">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>

    <link rel="stylesheet" type="text/css" href="/Public/projects/facego/style/base.css">
    <link rel="stylesheet" type="text/css" href="/Public/projects/facego/style/common_class.css">
    <!-- <link rel="stylesheet/less" type="text/css" href="/Public/projects/facego/style/common_class.less"> -->
    <link rel="stylesheet" type="text/css" href="/Public/projects/facego/style/index_dw.css">
    <!-- <link rel="stylesheet/less" type="text/css" href="/Public/projects/facego/style/index.less"> -->
</head>
<body>

<audio id="bgm" src="/Public/projects/facego/assets/media/bgm.mp3" loop="loop">
    您的浏览器不支持 audio 标签。
</audio>
<div class="ico-music1 ico"></div>

<div id="page1" segment class="bg-img">
    
    <div class="heart-block h-center">
        <div class="heart ico animHeart2"></div>
        <div class="go ico "></div>
    </div>
</div>
<div id="page2" segment class="none bg-img">
    <div class="baseline v-center">
        <div class="title" style="">
            <img src="/Public/projects/facego/assets/ui/dw_img_txt.png">
        </div>
        <div class="input-block bg-img">
            <img src="/Public/projects/facego/assets/ui/dw_input_block.png">
            <div class="ico plus v-center h-center" style="z-index: 3"></div>
            <div class="pic h-center" id="img_div">
                <img id="head-img" alt="">
            </div>
            <input type="file" id="uploader" style="display: none">
        </div>
        <div class="touch" id="touch">
            <img src="/Public/projects/facego/assets/ui/dw_btn_touch.png">
        </div>
    </div>
</div>
<div class="mask none">
    <div class="baseline v-center">
        <img src="/Public/projects/facego/assets/ui/dialog_error.png" class="error">
    </div>
</div>
<!-- ========================================================================= -->
<script src="/Public/projects/facego/libs/jquery-3.1.1.min.js"></script>
<script src="/Public/projects/facego/libs/exif.js"></script>

<!--WeiXin-->
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

<!--BaiDu 统计-->
<script src="/Public/js/common/baidutongji.js"></script>

<!-- <script src="/Public/projects/facego/libs/less.js"></script> -->
<!--common of all js file-->
<script src="/Public/projects/facego/js/common.js"></script>
<!--add self scrip file-->
<script>
$(function () {
    $('#page1').hide();
    $('#page2').show();
    var pic = '';
    $("#img_div").click(function () {
        if(window.__wxjs_is_wkwebview){
            wx.chooseImage({
                count: 1, // 默认9
                sizeType: ['original','compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                    for(var i=0; i<localIds.length;i++){
                        wx.getLocalImgData({
                            localId: localIds[i],
                            success:function(res){
                                var localData = res.localData;
                                $("#head-img").attr("src", localData);
                                pic = localData;
                            },
                            fail: function(res){
                                alert(res);
                            }
                        });
                    }
                }
            })
        }else{
            $("#uploader").click(); //隐藏了input:file样式后，点击头像就可以本地上传
            $("#uploader").on("change",function(){
                var file = this.files[0];
                if(!/image\/\w+/.test(file.type)){
                    alert("请确保文件为图像类型");
                    return false;
                }
                var reader=new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function() {
                    $("#head-img").attr("src", this.result);
                    pic = this.result;
                };
            });
        }
    });

    $('#touch').click(function(e){
        $(".mask img").attr('src', "/Public/projects/facego/wait.png")
        $(".mask").show()
        maskCanHide = false;
        ns.ajax({
            url: "dwfacecheck",
            type: "post",
            data: {
                img: pic
            },
            success: function(r){
                maskCanHide = true
                $(".mask").hide()
                if(r.code < 0){
                    $(".mask img").attr('src', "/Public/projects/facego/assets/ui/dialog_error.png")
                    $(".mask").show()
                }else{
                    window.location.href = "/Wap/Applications/dwfacego"
                }
            }
        })
    });

    var maskCanHide = true;
    $('.mask').click(function(e){
        maskCanHide && $(this).hide()
    });

    function toggleMusic(boo) {
        var music = $(".ico-music1");
        if(!boo){
            music.removeClass("animRotate");
            $("#bgm")[0].pause();
        }else{
            music.addClass("animRotate");
            $("#bgm")[0].play();
        }
    }
    $(".ico-music1").click(function () {
        toggleMusic(!$(this).hasClass("animRotate"));
    });

    setTimeout(function(){
        if(typeof WeixinJSBridge == 'undefined' ){
            toggleMusic(true)
            return
        }
        WeixinJSBridge.invoke('getNetworkType', {}, function(e) {
            toggleMusic(true)
        })
    },2000);
    wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: '{$appId}', // 必填，公众号的唯一标识
        timestamp: "{$timestamp}", // 必填，生成签名的时间戳
        nonceStr: '{$nonceStr}', // 必填，生成签名的随机串
        signature: '{$wxsha1}',// 必填，签名，见附录1
        jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline', 'chooseImage', 'getLocalImgData'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });
    wx.error(function(res){
        console.log(res);
    });
    wx.ready( function( e ){
        wx.onMenuShareAppMessage({
            title: "我是“端阳王”",
            desc: "端午习俗以雄黄抹额头，动动手指让自己化身“端阳王”吧！",
            link: "http://" + window.location.host + "/Wap/Applications/dwfaceindex",
            imgUrl: "http://" + window.location.host + "/Public/projects/facego/dwshare.png",
            type: 'link',
            dataUrl: '',
            success: function () {
            }
        });
        wx.onMenuShareTimeline({
            title: "端午习俗以雄黄抹额头，动动手指让自己化身“端阳王”吧！",
            link: "http://" + window.location.host + "/Wap/Applications/dwfaceindex",
            imgUrl: "http://" + window.location.host + "/Public/projects/facego/dwshare.png",
            success: function () {
            }
        });
    });

})
</script>

</body>
</html>